# -*- coding: utf-8 -*-
# @Time    : 2019/11/4 22:33
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : async_await.py

# python 为了将语义变得更加明确，就引入了async和await关键词用于定义或原生的协程
# from collections import Awaitable
import types

# async def downloader(url):
#     return "b1"

@types.coroutine
def downloader(url):
    yield "b2"

async def download_url(url):
    # do sometihings
    html = await downloader(url)   # 对比为yield from；await只能在async中出现
    return html

if __name__ == '__main__':
    coro = download_url("http://www.imooc.com")
    # next(None)  # 错误调用方式 原生协程
    coro.send(None)